layui.use(['form', 'layer', 'laydate'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    var laydate = layui.laydate;
    laydate.render({
        elem: '#expireDate',
        type: 'datetime'
    });

    form.on("submit(sendTask)", function () {
        var taskId = $("#Id").val();
        var taskName = $(".Name").val();
        var roleId = $(".RoleId").val();
        $.ajax({
            type: 'POST',
            url: '/Task/SendTask/',
            data: {
                Id: taskId,  //主键
                taskName: taskName,
                RoleId: roleId
            },
            dataType: "json",
            headers: {
                "X-CSRF-TOKEN-Gerald": $("input[name='AntiforgeryKey_Gerald']").val()
            },
            success: function (res) {//res为相应体,function为回调函数
                var alertIndex;
                if (res.ResultCode === 0) {
                    alertIndex = layer.alert(res.ResultMsg, { icon: 1 }, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                        top.layer.close(alertIndex);
                    });
                    //$("#res").click();//调用重置按钮将表单数据清空
                } else if (res.ResultCode === 102) {
                    alertIndex = layer.alert(res.ResultMsg, { icon: 5 }, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                        top.layer.close(alertIndex);
                    });
                }
                else {
                    layer.alert(res.ResultMsg, { icon: 5 });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
            }
        });
        return false;
    });

    form.on("submit(addTask)", function (data) {
        //获取防伪标记
        $.ajax({
            type: 'POST',
            url: '/Task/AddOrModify/',
            data: {
                Id: $("#Id").val(),  //主键
                Name: $(".Name").val(),
                Description: $(".Description").val(),
                EndDate: $("#expireDate").val()
            },
            dataType: "json",
            headers: {
                "X-CSRF-TOKEN-Gerald": $("input[name='AntiforgeryKey_Gerald']").val()
            },
            success: function (res) {//res为相应体,function为回调函数
                var alertIndex;
                if (res.ResultCode === 0) {
                    alertIndex = layer.alert(res.ResultMsg, { icon: 1 }, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                        top.layer.close(alertIndex);
                    });
                    //$("#res").click();//调用重置按钮将表单数据清空
                } else if (res.ResultCode === 102) {
                    alertIndex = layer.alert(res.ResultMsg, { icon: 5 }, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                        top.layer.close(alertIndex);
                    });
                }
                else {
                    layer.alert(res.ResultMsg, { icon: 5 });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
            }
        });
        return false;
    });

    //<button id="btnRunVideo">打开视频</button>
    //var scriptArgs = document.getElementById('testScript').getAttribute('data');

    //alert(scriptArgs);
    //var loadstr = '<video width="100%" height="100%"  controls="controls" autobuffer="autobuffer"  autoplay="autoplay" loop="loop"><source src="' + scriptArgs + '" type="video/mp4"></source></video>';

    //var loadstr = '<video width="100%" height="100%"  controls="controls" autobuffer="autobuffer"  autoplay="autoplay" loop="loop"><source src="http://localhost:8089/1.mp4" type="video/mp4"></source></video>';

    //$('#btnRunVideo').click(function () {
    //    layer.open({
    //        type: 1,
    //        area: ['500px', '70%'],
    //        title: '培训视频',
    //        content: loadstr,
    //    });
    //})
});